ActiveRecord::Base.guid_generator = :mysql

module ActiveRecord::ConnectionAdapters::SchemaStatements
  
  def create_uuid_table(table_name, options = {})
    create_table table_name, options.reverse_merge({ :id => false }) do |t|
      t.string :id, :limit => 36
      yield t
    end
    execute("ALTER TABLE #{table_name} ADD PRIMARY KEY (id)")
  end
  
end

module ActiveRecord::ConnectionAdapters

  class Table
    def references_uuid(*args)
       options = args.extract_options!
       polymorphic = options.delete(:polymorphic)
       args.each do |col|
         @base.add_column(@table_name, "#{col}_id", :string, options.reverse_merge({ :limit => 36 }))
         @base.add_column(@table_name, "#{col}_type", :string, polymorphic.is_a?(Hash) ? polymorphic : options) unless polymorphic.nil?
      end
    end
  end
  
end